package com.dubbo;

/**
 * 将所有成员变量和代码块构造方法按顺序合成为一个init方法执行
 */
public class Init {
    {
        a = 20;
    }

    public Init(int a) {
        this.a = a;
    }

    private int a = 10;

    public Init() {}

    public static void main(String[] args) throws ClassNotFoundException, NoSuchFieldException {
        //Init init = new Init(30);
        //Class class_ = Class.forName("com.dubbo.Init");
        Init init = new Init();
        System.out.println(init.a);

    }
}

/**
 * Compiled from "Init.java"
 * public class com.dubbo.Init {
 *   public com.dubbo.Init(int);
 *   public static void main(java.lang.String[]);
 * }
 * cqh@cqh-ThinkBook:~/IdeaProjects/study/jvm/target/classes/com/dubbo$ javap -v Init.class
 * Classfile /home/cqh/IdeaProjects/study/jvm/target/classes/com/dubbo/Init.class
 *   Last modified 2022-9-18; size 533 bytes
 *   MD5 checksum f89b13c6ae775bc3493179f06b1a5c4d
 *   Compiled from "Init.java"
 * public class com.dubbo.Init
 *   minor version: 0
 *   major version: 52
 *   flags: ACC_PUBLIC, ACC_SUPER
 * Constant pool:
 *    #1 = Methodref          #5.#23         // java/lang/Object."<init>":()V
 *    #2 = Fieldref           #3.#24         // com/dubbo/Init.a:I
 *    #3 = Class              #25            // com/dubbo/Init
 *    #4 = Methodref          #3.#26         // com/dubbo/Init."<init>":(I)V
 *    #5 = Class              #27            // java/lang/Object
 *    #6 = Utf8               a
 *    #7 = Utf8               I
 *    #8 = Utf8               <init>
 *    #9 = Utf8               (I)V
 *   #10 = Utf8               Code
 *   #11 = Utf8               LineNumberTable
 *   #12 = Utf8               LocalVariableTable
 *   #13 = Utf8               this
 *   #14 = Utf8               Lcom/dubbo/Init;
 *   #15 = Utf8               MethodParameters
 *   #16 = Utf8               main
 *   #17 = Utf8               ([Ljava/lang/String;)V
 *   #18 = Utf8               args
 *   #19 = Utf8               [Ljava/lang/String;
 *   #20 = Utf8               init
 *   #21 = Utf8               SourceFile
 *   #22 = Utf8               Init.java
 *   #23 = NameAndType        #8:#28         // "<init>":()V
 *   #24 = NameAndType        #6:#7          // a:I
 *   #25 = Utf8               com/dubbo/Init
 *   #26 = NameAndType        #8:#9          // "<init>":(I)V
 *   #27 = Utf8               java/lang/Object
 *   #28 = Utf8               ()V
 * {
 *   public com.dubbo.Init(int);
 *     descriptor: (I)V
 *     flags: ACC_PUBLIC
 *     Code:
 *       stack=2, locals=2, args_size=2
 *          0: aload_0
 *          1: invokespecial #1                  // Method java/lang/Object."<init>":()V
 *          4: aload_0
 *          5: bipush        10
 *          7: putfield      #2                  // Field a:I
 *         10: aload_0
 *         11: bipush        20
 *         13: putfield      #2                  // Field a:I
 *         16: aload_0
 *         17: iload_1
 *         18: putfield      #2                  // Field a:I
 *         21: return
 *       LineNumberTable:
 *         line 9: 0
 *         line 4: 4
 *         line 6: 10
 *         line 10: 16
 *         line 11: 21
 *       LocalVariableTable:
 *         Start  Length  Slot  Name   Signature
 *             0      22     0  this   Lcom/dubbo/Init;
 *             0      22     1     a   I
 *     MethodParameters:
 *       Name                           Flags
 *       a
 *
 *   public static void main(java.lang.String[]);
 *     descriptor: ([Ljava/lang/String;)V
 *     flags: ACC_PUBLIC, ACC_STATIC
 *     Code:
 *       stack=3, locals=2, args_size=1
 *          0: new           #3                  // class com/dubbo/Init
 *          3: dup
 *          4: bipush        30
 *          6: invokespecial #4                  // Method "<init>":(I)V
 *          9: astore_1
 *         10: return
 *       LineNumberTable:
 *         line 14: 0
 *         line 15: 10
 *       LocalVariableTable:
 *         Start  Length  Slot  Name   Signature
 *             0      11     0  args   [Ljava/lang/String;
 *            10       1     1  init   Lcom/dubbo/Init;
 *     MethodParameters:
 *       Name                           Flags
 *       args
 * }
 * SourceFile: "Init.java"
 */